// 与foreach非常相似，但是需要一个结果来接受
Array.prototype.map2 = function (fun, thisArg) {
    if (typeof fun !== 'function') {
        throw new TypeError(`${fun} is not function`)
    }

    let len = this.length
    let result = new Array()
    for (let i = 0; i < len; i++) {
        if (Object.prototype.hasOwnProperty.call(this, i)) {
            result[i] = fun.call(thisArg, this[i], i, this)
        }
    }

    return result
}
let arr = [1, undefined, 4, 5]

let result = arr.map2((item) => console.log(item))//1，4，5

let arr1=[1,3, ,4,5,6]
let arr2= arr1.map2(item=>item+1)//当map遍历到空位子时会跳过，直接不会遍历[ 2, 4, <1 empty item>, 5, 6, 7 ]
console.log(arr2);[ 2, 4, , 5, 6, 7 ]
console.log(arr1.map(item=>item+1));

